package sechomework;

import java.util.*;

public class SecSort {
    public static void main(String[] args) {
        Random random=new Random();
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<5;i++){
            list.add(i,random.nextInt(100));
        }
        System.out.println("list排序前："+list);
        Collections.sort(list);
        System.out.println("list排序后："+list);
        Collections.reverse(list);
        System.out.println("list排序翻转后："+list);

        List<String> list1=new ArrayList<>();
        list1.add("tom");
        list1.add("jerry");
        list1.add("bob");
        list1.add("Tyrande");
        list1.add("Malfurion");
        list1.add("Illidan");
        System.out.println("list1排序前："+list1);
        Collections.sort(list1);//按首字母的ASCII码升序排列
        System.out.println("list1排序后："+list1);


        List<String> list2=new ArrayList<>();
        list2.add("骑手战鹰");
        list2.add("拔罐王捷豹");
        list2.add("鱼妹妹俞俐均");
        list2.add("连笑");
        System.out.println("list2排序前："+list2);
        list2.sort((o1, o2) -> o1.length()-o2.length());
        System.out.println("list2排序后："+list2);

        List<Point> list3=new ArrayList<>();
        list3.add(new Point(3,9));
        list3.add(new Point(3,6));
        list3.add(new Point(6,9));
        list3.add(new Point(7,8));
        list3.add(new Point(6,1));
        System.out.println("list3排序前："+list3);
        list3.sort((o1, o2) -> {
            if(o1.getX()==o2.getX()){
                return o1.getY()-o2.getY();
            }else{
                return o1.getX()-o2.getX();
            }
        });
        System.out.println("list3排序后："+list3);


    }
}
